package client

import (
	. "chess_platform/internal/common"
	"chess_platform/models/client"
	"chess_platform/models/partner"
	"chess_platform/models/pc"
)

//一些杂七杂八的
type OtherController struct {
	GrantController
}

func (b *OtherController) URLMapping() {
	b.Mapping("ListOtherConf", b.ListOtherConf)
	b.Mapping("ListHorse", b.ListHorse)
}

// @Title 其它配置列表(开屏广告,客服,合作)
// @Description 其它配置列表(开屏广告,客服,合作)
// @Param   type     body   int     true       "类型,0-所有，1-跑马灯,2-开屏广告,3-客服,4-合作(4-代理,5-商务))"
// @Success 0 {object} []common.OtherConf 其它配置列表
// @router /list-other-conf [post]
func (b *OtherController) ListOtherConf() {
	type Params struct {
		Type int64 `json:"type" valid:"Range(0,4)"`
	}
	var p Params
	if !b.DecodeParams(&p) {
		return
	}
	if !b.ValidParams(&p) {
		return
	}
	data, err := client.ListOtherConf(p.Type)
	if err != nil {
		LogClient.Error(b.DatabaseError(err.Error()))
		return
	}
	groupId := partner.GetPlayerGroupId(b.Uid)
	wechatAgent, wechatBusiness := pc.PbUserWechatById(groupId)
	if wechatBusiness != "" || wechatAgent != "" {
		for k, v := range data {
			if v.Type == 4 && wechatAgent != "" {
				data[k].Value = wechatAgent
			} else if v.Type == 5 && wechatBusiness != "" {
				data[k].Value = wechatBusiness
			}
		}
	}

	b.Res.Data = data
	b.ResponseSuccess()
}

// @Title 跑马灯列表
// @Description 跑马灯列表
// @Success 0 {object} []common.Horse   跑马灯列表
// @router /list-horse  [post]
func (b *OtherController) ListHorse() {
	//跑马灯类型,1-游戏客户端, 2-代理助手
	data, err := client.ListHorse(1)
	if err != nil {
		LogClient.Error(b.DatabaseError(err.Error()))
		return
	}

	b.Res.Data = data
	b.ResponseSuccess()
}
